#!/bin/bash

#485测试初始化
if [ ! -d "/sys/class/gpio/gpio28" ]; then
    echo 28 > /sys/class/gpio/export
    echo "out" > /sys/class/gpio/gpio28/direction
fi

if [ ! -d "/sys/class/gpio/gpio29" ]; then
    echo 29 > /sys/class/gpio/export
    echo "out" > /sys/class/gpio/gpio29/direction
fi

echo "485 success"

#422测试初始化：除了发送端和485共用需要拉高，接收端不需要操作

echo "422 success"

#232测试初始化：无需初始化操作

echo "232 success"

#can测试初始化：无需初始化操作

echo "can success"

#4-20ma 输出 初始化操作
if [ ! -d "/sys/class/pwm/pwmchip1/pwm0" ]; then
    echo 0 > /sys/class/pwm/pwmchip1/export
    echo 1000000 > /sys/class/pwm/pwmchip1/pwm0/period
    echo 1000000 > /sys/class/pwm/pwmchip1/pwm0/duty_cycle
    echo "normal" > /sys/class/pwm/pwmchip1/pwm0/polarity
    echo 1 > /sys/class/pwm/pwmchip1/pwm0/enable
fi

if [ ! -d "/sys/class/pwm/pwmchip2/pwm0" ]; then
    echo 0 > /sys/class/pwm/pwmchip2/export
    echo 1000000 > /sys/class/pwm/pwmchip2/pwm0/period
    echo 1000000 > /sys/class/pwm/pwmchip2/pwm0/duty_cycle
    echo "normal" > /sys/class/pwm/pwmchip2/pwm0/polarity
    echo 1 > /sys/class/pwm/pwmchip2/pwm0/enable
fi

echo "4-20mA success"

#干接点输入初始化操作：
if [ ! -d "/sys/class/gpio/gpio136" ]; then
    echo 136 > /sys/class/gpio/export
    echo "in" > /sys/class/gpio/gpio136/direction
fi

if [ ! -d "/sys/class/gpio/gpio137" ]; then
    echo 137 > /sys/class/gpio/export
    echo "in" > /sys/class/gpio/gpio137/direction
fi

echo "note in success"

#干接点输出初始化操作：
if [ ! -d "/sys/class/gpio/gpio135" ]; then
    echo 135 > /sys/class/gpio/export
    echo "out" > /sys/class/gpio/gpio135/direction
fi

if [ ! -d "/sys/class/gpio/gpio129" ]; then
    echo 129 > /sys/class/gpio/export
    echo "out" > /sys/class/gpio/gpio129/direction
fi

echo "note out success"

# export PATH=/data:$PATH 
export PATH=/userfs:$PATH 

if [ ! -d "/userfs" ]; then
  mkdir /userfs
fi
cd /userfs

echo "init success"